from flask import Blueprint, render_template, request
from applications.common import curd
from applications.common.utils.rights import authorize
from applications.models import Book, Page
bp = Blueprint('read', __name__, url_prefix='/read')


@bp.get('/<int:bookid>/<int:pageid>')
#@authorize("zbook:book:main")
def main(bookid, pageid):
    if not bookid:
        bookid = 1
    if not pageid:
        pageid = 1
    print(f"/read param router bookid: {bookid}, page: {pageid}")
    book = curd.get_one_by_id(Book, bookid)
    page = curd.get_one_by_id(Page, pageid)
    return render_template('zbook/read.html', book=book, page=page)

